<?php
/**
 * Created by PhpStorm.
 * User: liu85
 * Date: 2019/2/23
 * Time: 17:10
 */

namespace app\common\model;


class Product extends Base
{
    public $defaultFields = 'id,name,icon,quota,link,term,loanTime,interestRate,clickCount,isHot,isNew,sort,created';

    /**
     * 获取最新列表
     * @param $limit int
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getNewItemList($limit = 0)
    {
        $map = [
            'isNew' => 1,
        ];
        $obj = $this->where($map)->field($this->defaultFields)->order('sort desc,created desc,id desc');
        if($limit){
            $obj = $obj->limit($limit);
        }
        return $obj->select();
    }

    /**
     * 获取最热列表
     * @param int $limit
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getHotItemList($limit = 0)
    {
        $map = [
            'isHot' => 1,
        ];
        $obj = $this->where($map)->field($this->defaultFields)->order('sort desc,created desc,id desc');
        if($limit){
            $obj = $obj->limit($limit);
        }
        return $obj->select();
    }
}